package com.goldcn.user.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.goldcn.common.consts.RestConst;
import com.goldcn.common.exception.ServiceException;
import com.goldcn.common.model.DataResult;
import com.goldcn.common.util.CommonUtils;
import com.goldcn.common.util.IdGen;
import com.goldcn.config.ProConstants;
import com.goldcn.interceptor.SystemContext;
import com.goldcn.user.dao.*;
import com.goldcn.user.dto.SubjectInfoDto;
import com.goldcn.user.model.*;
import com.goldcn.util.CommonTools;
import com.goldcn.util.HttpUtil;
import com.goldcn.util.ListUtils;
import com.google.common.base.Objects;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 1111 on 2016/11/23.
 */
@Service
@Transactional
public class HomepageService {
    @Autowired
    SubjectMapper subjectMapper;

    @Autowired
    SubjectGoodsMapper subjectGoodsMapper;

    @Autowired
    HomepageMapper homepageMapper;

    @Autowired
    ConfigMapper configMapper;

    @Autowired
    RestTemplate restTemplate;


    @Autowired
    CompanyInfoMapper companyInfoMapper;

    private Logger logger = Logger.getLogger(HomepageService.class);
    /**
     * @param subjectInfoDto
     * @param state          1添加，2修改
     * @return id
     * @throws Exception
     */

    public Object addOrUpdateSubject(SubjectInfoDto subjectInfoDto, int state) throws Exception {
        logger.info("subjectInfoDto==="+subjectInfoDto);
        logger.info("subject==="+subjectInfoDto.getSubject());
        logger.info("subjectGoodsList==="+subjectInfoDto.getSubjectGoodsList());
        Subject subject = new Subject();
        BeanUtils.copyProperties(subject, subjectInfoDto.getSubject());
        // 兼容平台商城和小商城 updated 2018
        Long companyID = subject.getCompanyID() != null ? subject.getCompanyID() : SystemContext.getCompanyID();
        if (state == 1) {
            Subject subject1 = subjectMapper.selectByTitle(subject.getTitle(), companyID);
            if (subject1 != null) {
                throw new ServiceException("该标题已经存在：" + subject1.getTitle(), RestConst.ErrorCode.FORM_FAIL);
            }
            subject.setId(IdGen.get().nextId());
            subject.setAddTime(CommonUtils.getCurTimestamp());
            subject.setCompanyID(companyID);
            subjectMapper.insertSelective(subject);
        } else if (state == 2) {
            subjectMapper.updateByPrimaryKeySelective(subject);
        }
        if (subjectInfoDto.getSubjectGoodsList().isEmpty()) {
            throw new ServiceException("请添加主题下的商品", RestConst.ErrorCode.FORM_FAIL);
        }
        JSONArray jsonArray = JSONArray.fromObject(subjectInfoDto.getSubjectGoodsList());
        List<SubjectGoods> subjectGoodsList = (List) JSONArray.toCollection(jsonArray, SubjectGoods.class);
        batchInsertGoods(subject.getId(), subjectGoodsList);

        if (state == 2) {
            updateSubjectInHomepage(subject.getId());
        }

        return subject.getId();
    }

    //删除主题
    public Object deleteSubject(Long id) {
        List<Homepage> homepageList = homepageMapper.selectBySubjectID(id);
        String subjectString = homepageMapper.selectByPrimaryKey(7).getObejctList();
        if (homepageList.size() > 0 || subjectString.indexOf(id.toString()) > 0) {
            throw new ServiceException("该主题已经在首页使用，不可删除", RestConst.ErrorCode.FORM_FAIL);
        }
        DataResult result = HttpUtil.httpGet(ProConstants.operateClazzSubject + id, restTemplate);
        if (result.getIsSuccess() == 1) {
            if (!result.getData().toString().equals("0")) {
                throw new ServiceException("该主题已在分类专题中使用，不可删除", RestConst.ErrorCode.FORM_FAIL);
            }
        } else {
            throw new ServiceException("调用bank服务查询分类专题错误，请重试", RestConst.ErrorCode.SERVICE_FAIL);
        }

        subjectGoodsMapper.deleteBySubjectID(id);
        subjectMapper.deleteByPrimaryKey(id);
        return "success";
    }

    //查询所有主题列表
    public PageInfo selectSubjectList(int pageNum, int pageSize, Long shopID) {
        PageHelper.startPage(pageNum, pageSize);
        // 兼容平台商城和小商城 updated 2018
        Long id = shopID != null ? shopID : SystemContext.getCompanyID();
        List<Subject> subjectList = subjectMapper.selectAllList(id);
        PageInfo<Subject> page = new PageInfo(subjectList);
        return page;
    }

    //按专题id查询专题详情
    public SubjectInfoDto selectSubjectInfo(Long subjectID, Long userID) {
        SubjectInfoDto infoDto = new SubjectInfoDto();
        infoDto.setSubject(subjectMapper.selectByPrimaryKey(subjectID));
        List<SubjectGoods> subjectGoodsList = subjectGoodsMapper.selectBySubjectID(subjectID);
        if (subjectGoodsList.size() == 0) {
            return infoDto;
        }
        List<Long> goodsIDList = new ArrayList<>();
        for (SubjectGoods subjectGoods : subjectGoodsList) {
            goodsIDList.add(subjectGoods.getGoodsID());
        }
        //获取最新商品信息
        int size1 = subjectGoodsList.size();
        Map<String, Map<String, String>> goodsList = selectByGoodsIDs(goodsIDList);
        for (int i = subjectGoodsList.size() - 1; i >= 0; i--) {
            String currGoodsID = subjectGoodsList.get(i).getGoodsID().toString();
            subjectGoodsList.get(i).setGoodsName(goodsList.get(currGoodsID).get("name"));
            subjectGoodsList.get(i).setGoodsTitle(goodsList.get(currGoodsID).get("title"));
            subjectGoodsList.get(i).setImg(goodsList.get(currGoodsID).get("img"));
            subjectGoodsList.get(i).setPrdNo(goodsList.get(currGoodsID).get("prdNo"));
            subjectGoodsList.get(i).setLabelName(goodsList.get(currGoodsID).get("labelName"));
        }


        //获取主题下商品得实时价格
        Map<String, Object> param = getGoodsPrice(goodsIDList, userID);

        //价格为零或者为null表示商品已经失效,则删除
        for (int i = subjectGoodsList.size() - 1; i >= 0; i--) {
            if (param.get(subjectGoodsList.get(i).getGoodsID().toString()) == null || "0".equals(param.get(subjectGoodsList.get(i).getGoodsID().toString()))) {
                subjectGoodsMapper.deleteByPrimaryKey(subjectGoodsList.get(i).getId());
                subjectGoodsList.remove(subjectGoodsList.get(i));
            } else {
                subjectGoodsList.get(i).setPrice(param.get(subjectGoodsList.get(i).getGoodsID().toString()).toString());
            }
        }
        //如果该专题有商品失效，并且该专题已经作为首页ID为8的展示则更新
        int size2 = subjectGoodsList.size();
        if (size2 < size1) {
            Integer homePageID = CommonTools.getExtInt(restTemplate, "middlaa");
            /*Homepage homepage = homepageMapper.selectByPrimaryKey(homePageID);
            if (homepage.getSubjectID() != null) {
                if (homepage.getSubjectID().equals(subjectID)) {
                    Subject subject = subjectMapper.selectByPrimaryKey(subjectID);
                    updateHomepageMiddle(subject, homePageID);
                }
            }*/
        }
        infoDto.setSubjectGoodsList(subjectGoodsList);
        return infoDto;
    }


    //按专题id查询专题详情, shop_version 2018
    public SubjectInfoDto selectShopSubjectInfo(Long subjectID, Long shopID) {
        SubjectInfoDto infoDto = new SubjectInfoDto();
        infoDto.setSubject(subjectMapper.selectByPrimaryKey(subjectID));
        List<SubjectGoods> subjectGoodsList = subjectGoodsMapper.selectBySubjectID(subjectID);
        if (subjectGoodsList.size() == 0) {
            return infoDto;
        }
        List<Long> goodsIDList = new ArrayList<>();
        for (SubjectGoods subjectGoods : subjectGoodsList) {
            goodsIDList.add(subjectGoods.getGoodsID());
        }
        //获取最新商品信息
        int size1 = subjectGoodsList.size();
        Map<String, Map<String, String>> goodsList = selectByGoodsIDsShop(goodsIDList,shopID);

        List<SubjectGoods> inexistenceGoods = new ArrayList<>();
        for (int i = subjectGoodsList.size() - 1; i >= 0; i--) {
            String currGoodsID = subjectGoodsList.get(i).getGoodsID().toString();
            if(CommonTools.checkMapKeyExist(currGoodsID,goodsList)){
                subjectGoodsList.get(i).setGoodsName(goodsList.get(currGoodsID).get("name"));
                subjectGoodsList.get(i).setGoodsTitle(goodsList.get(currGoodsID).get("title"));
                subjectGoodsList.get(i).setImg(goodsList.get(currGoodsID).get("img"));
                subjectGoodsList.get(i).setPrdNo(goodsList.get(currGoodsID).get("prdNo"));
                subjectGoodsList.get(i).setLabelName(goodsList.get(currGoodsID).get("labelName"));
                subjectGoodsList.get(i).setSeqno(MapUtils.getInteger(goodsList.get(currGoodsID),"seqno",0));
            }else{
                inexistenceGoods.add(subjectGoodsList.get(i));
            }

        }
        //清除已下架或者删除的商品
        if(CollectionUtils.isNotEmpty(inexistenceGoods) && inexistenceGoods.size()>0){
            subjectGoodsList.removeAll(inexistenceGoods);
        }



        //获取主题下商品得实时价格
        Map<String, Object> param = getShopGoodsPrice(goodsIDList, shopID);

        //价格为零或者为null表示商品已经失效,则删除
        for (int i = subjectGoodsList.size() - 1; i >= 0; i--) {
            if (param.get(subjectGoodsList.get(i).getGoodsID().toString()) == null || "0".equals(param.get(subjectGoodsList.get(i).getGoodsID().toString()))) {
                subjectGoodsMapper.deleteByPrimaryKey(subjectGoodsList.get(i).getId());
                subjectGoodsList.remove(subjectGoodsList.get(i));
            } else {
                subjectGoodsList.get(i).setPrice(param.get(subjectGoodsList.get(i).getGoodsID().toString()).toString());
            }
        }
        //如果该专题有商品失效，并且该专题已经作为首页ID为8的展示则更新
        int size2 = subjectGoodsList.size();
        if (size2 < size1) {

            Map<String, Object> para = new HashMap<>();
            para.put("companyID", shopID);
            para.put("type", 1);
            para.put("homeKey", "middlaa");//首页Top图片

            Homepage homepage = homepageMapper.selectByCondition(para);
            if (homepage == null) {
                throw new ServiceException("模板配置没有找到，参数有误", RestConst.ErrorCode.FORM_FAIL);
            }
            if (homepage.getSubjectID() != null) {
                if (homepage.getSubjectID().equals(subjectID)) {
                    Subject subject = subjectMapper.selectByPrimaryKey(subjectID);
                    updateHomepageMiddle(subject, homepage.getId());
                }
            }
        }
        ListUtils.sort(subjectGoodsList,true,"seqno");
        infoDto.setSubjectGoodsList(subjectGoodsList);
        return infoDto;
    }

    private Map<String, Map<String, String>> selectByGoodsIDs(List<Long> goodsIDList) {

        DataResult result = HttpUtil.httpPost(ProConstants.getGoodsByGoodsIDs, goodsIDList, restTemplate);

        return (Map<String, Map<String, String>>) result.getData();
    }

    private Map<String, Map<String, String>> selectByGoodsIDsShop(List<Long> goodsIDList,Long shopID) {

        DataResult result = HttpUtil.httpPost(ProConstants.getGoodsByGoodsIDsShop+"/"+shopID, goodsIDList, restTemplate);

        return (Map<String, Map<String, String>>) result.getData();
    }

    //查询首页所有专题数据（muban：1,2）
    public List<Homepage> selectHomepgeAll(int muban, Long userID) {

        Map<String, Object> param = new HashMap<>();
        param.put("muban", muban);
        param.put("companyID", SystemContext.getCompanyID());
        List<Homepage> homepageList = homepageMapper.selectAll(param);
        if (muban == 2) {
            List<Long> goodsIDList = new ArrayList<>();
            for (Homepage homepage : homepageList) {
                if (homepage.getSubjectID() != null) {
                    goodsIDList.add(homepage.getSubjectID());
                }
            }
            if (goodsIDList.size() > 0) {
                Map<String, Object> price = getGoodsPrice(goodsIDList, userID); //获取商品对应的实时价格
                for (Homepage homepage : homepageList) {
                    if (homepage.getSubjectID() != null) {
                        Object goodsPrice = price.get(homepage.getSubjectID().toString());
                        if (goodsPrice != null && !goodsPrice.equals("0")) {
                            JSONObject jsonObject = JSONObject.fromObject(homepage.getObejctList());
                            jsonObject.put("price", goodsPrice.toString());
                            homepage.setObejctList(jsonObject.toString());
                            //homepageMapper.updateByPrimaryKeySelective(homepage);
                        }
                    }
                }
            }
        }
        return homepageList;
    }

    //查询首页所有专题数据（muban：1,2）
    public List<Homepage> selectHomepgeAll(int muban, Long userID, Long shopID) {

        Map<String, Object> param = new HashMap<>();
        param.put("muban", muban);
        param.put("companyID", shopID);//SystemContext.getCompanyID()
        List<Homepage> homepageList = homepageMapper.selectAll(param);
        if (muban == 2) {
            List<Long> goodsIDList = new ArrayList<>();
            for (Homepage homepage : homepageList) {
                if (homepage.getSubjectID() != null) {
                    goodsIDList.add(homepage.getSubjectID());
                }
            }
            if (goodsIDList.size() > 0) {
                Map<String, Object> price = getShopGoodsPrice(goodsIDList, shopID); //获取商品对应的实时价格
                for (Homepage homepage : homepageList) {
                    if (homepage.getSubjectID() != null) {
                        Object goodsPrice = price.get(homepage.getSubjectID().toString());
                        if (goodsPrice != null && !goodsPrice.equals("0")) {
                            JSONObject jsonObject = JSONObject.fromObject(homepage.getObejctList());
                            jsonObject.put("price", goodsPrice.toString());
                            homepage.setObejctList(jsonObject.toString());
                            //homepageMapper.updateByPrimaryKeySelective(homepage);
                        }
                    }
                }
            }
        }
        return homepageList;
    }


    //按id查询首页专题数据
    public Homepage selectHomepageByID(Integer id) {
        return homepageMapper.selectByPrimaryKey(id);
    }

    //更新首页middle主题（id{1,2,3,4,5,8}）
    public Object updateHomepageMiddle(Subject subject, Integer id) {
        if ((id > 5 && id != 8) || id < 1) {
            throw new ServiceException("参数传入错误", RestConst.ErrorCode.FORM_FAIL);
        }
        Homepage homepage = homepageMapper.selectByPrimaryKey(id);
        homepage.setSubjectID(subject.getId());
        homepage.setTitle(subject.getTitle());
        homepage.setSubtitle(subject.getSubtitle());
        homepage.setVersion(homepage.getVersion() + 1);
        if (id == 8) {
            List<SubjectGoods> subjectGoodsList = subjectGoodsMapper.selectBySubjectID(subject.getId());
            List<JSONObject> jsonObjectList = new ArrayList<>();
            for (SubjectGoods subjectGoods : subjectGoodsList) {
                JSONObject jsonObject = JSONObject.fromObject(subjectGoods);
                jsonObject.put("goodsID", subjectGoods.getGoodsID().toString());
                jsonObjectList.add(jsonObject);
            }

            JSONObject jsonObject = new JSONObject();
            jsonObject.put("coverImg", subject.getCoverImg());
            jsonObject.put("subjectGoodsList", jsonObjectList);
            homepage.setObejctList(jsonObject.toString());
        } else {
            homepage.setObejctList(subject.getCoverImg());
        }
        homepage.setId(id);
        homepageMapper.updateByPrimaryKeySelective(homepage);
        return homepageMapper.selectByPrimaryKey(id);
    }

    //更新首页Banner
    public Object updateHomepageBanner(JSONObject jsonObject) {
        Homepage homepage = homepageMapper.selectByPrimaryKey(6);
        homepage.setVersion(homepage.getVersion() + 1);
        homepage.setObejctList(jsonObject.toString());
        homepage.setId(6);
        homepageMapper.updateByPrimaryKeySelective(homepage);
        return homepageMapper.selectByPrimaryKey(6);
    }

    //更新首页更多专题项
    public Object updateHomepageMoreTitle(JSONObject jsonObject) {
        Homepage homepage = homepageMapper.selectByPrimaryKey(7);
        homepage.setVersion(homepage.getVersion() + 1);
        homepage.setObejctList(jsonObject.toString());
        homepage.setId(7);
        homepageMapper.updateByPrimaryKeySelective(homepage);
        return homepageMapper.selectByPrimaryKey(7);
    }

    /**
     * -------------------------------------------模板2----------------------------------------------
     */
    //设置默认模板
    public Object setMuban(Long oID, Integer muban) {
        if (muban != 1 && muban != 2) {
            throw new ServiceException("模板参数传入有误", RestConst.ErrorCode.FORM_FAIL);
        }
        Config config = configMapper.selectByPrimaryKey(oID);
        if (config == null) {
            Config cf = new Config();
            cf.setCompanyInfoID(oID);
            cf.setTempNO(muban.toString());
            configMapper.insertSelective(cf);
        } else {
            config.setTempNO(muban.toString());
            configMapper.updateByPrimaryKeySelective(config);
        }
        return "success";
    }

    //查询默认模板
    public Object getMuban(Long oID) {
        Config config = configMapper.selectByPrimaryKey(oID);
        if (config != null) {
            return config.getTempNO();
        } else {
            return null;
        }
    }

    //查询默认模板,小商城 2018
    public Object getMubanV2(Long oID) {
        CompanyInfo config = companyInfoMapper.selectByPrimaryKey(oID);
        if (config != null) {
            return config.getTempNO();
        } else {
            return null;
        }

    }

    //更新模板2的Banner和更多专题（type：1banner，2更多专题）
    public Object updateHomepageMuban2Banner(JSONObject jsonObject, int type) {
        Homepage homepage = new Homepage();
        Integer homePageID;
        switch (type) {
            case 1:
                homePageID = CommonTools.getExtInt(restTemplate, "uTop");//首页Top图片
                break;
            case 2:
                homePageID = CommonTools.getExtInt(restTemplate, "uBottom");//专题
                break;
            default:
                throw new ServiceException("type传入有误", RestConst.ErrorCode.FORM_FAIL);
        }
        homepage = homepageMapper.selectByPrimaryKey(homePageID);
        homepage.setVersion(homepage.getVersion() + 1);
        homepage.setObejctList(jsonObject.toString());
        homepageMapper.updateByPrimaryKeySelective(homepage);
        return homepageMapper.selectByPrimaryKey(homepage.getId());
    }


    //更新模板2的Banner和更多专题（type：1banner，2更多专题）
    //装修小商城 2018-4-12
    public Object updateHomepageMuban2BannerShop(JSONObject jsonObject, int type, Long shopID) {
        Map<String, Object> para = new HashMap<>();
        para.put("companyID", shopID);
        para.put("type", type);
        Homepage homepage = null;
        switch (type) {
            case 1:
                para.put("homeKey", "uTop");//首页Top图片
                break;
            case 2:
                para.put("homeKey", "uBottom");//专题
                break;
            default:
                throw new ServiceException("type传入有误", RestConst.ErrorCode.FORM_FAIL);
        }
        homepage = homepageMapper.selectByCondition(para);
        if (homepage == null) {
            throw new ServiceException("模板配置没有找到，参数有误", RestConst.ErrorCode.FORM_FAIL);
        }
        homepage.setVersion(homepage.getVersion() + 1);
        homepage.setObejctList(jsonObject.toString());
        homepageMapper.updateByPrimaryKeySelective(homepage);
        return homepageMapper.selectByPrimaryKey(homepage.getId());
    }


    //更新模板2首页的middle主题数据(id 为10或者11)
    public Object updateHomepageMuban2Middle(Homepage homepage) {
        if (homepage.getId() != 10 && homepage.getId() != 11) {
            throw new ServiceException("传入id有误", RestConst.ErrorCode.FORM_FAIL);
        }
        if (homepage.getSubjectID() == null || homepage.getSubjectID() == 0) {
            throw new ServiceException("必须选择一个商品", RestConst.ErrorCode.FORM_FAIL);
        }
        if (!Objects.equal(SystemContext.getCompanyID(), ProConstants.SXPACCOUNTID)) {
            String code = Objects.equal(homepage.getId(), 10) ? "uMiddl01" : "uMiddl02";
            Integer uMiddl01 = CommonTools.getExtInt(restTemplate, code);
            if (null == uMiddl01) {
                throw new ServiceException("传入id有误", RestConst.ErrorCode.FORM_FAIL);
            }
            if (homepage.getSubjectID() == null || homepage.getSubjectID() == 0) {
                throw new ServiceException("必须选择一个商品", RestConst.ErrorCode.FORM_FAIL);
            }
            homepage.setId(uMiddl01);
        }
        homepageMapper.updateByPrimaryKeySelective(homepage);
        return homepageMapper.selectByPrimaryKey(homepage.getId());
    }

    //更新模板2首页的middle主题数据(id 为10或者11)
    public Object updateHomepageMuban2MiddleShop(Homepage homepage, Long shopID) {
        if (homepage.getSubjectID() == null || homepage.getSubjectID() == 0) {
            throw new ServiceException("必须选择一个商品", RestConst.ErrorCode.FORM_FAIL);
        }
        homepageMapper.updateByPrimaryKeySelective(homepage);
        return homepageMapper.selectByPrimaryKey(homepage.getId());
    }

    /**
     * --------------------------------------------模板2-------------------------------------------------
     */

    //批量插入subjectGoods
    private void batchInsertGoods(Long subjectId, List<SubjectGoods> subjectGoodsList) {
        subjectGoodsMapper.deleteBySubjectID(subjectId);
        int i=0;
        for (SubjectGoods sg : subjectGoodsList) {
            i=i+1;
            sg.setId(IdGen.get().nextId());
            sg.setSubjectID(subjectId);
            sg.setSeqno(i);
        }
        if (subjectGoodsList.size() > 0) {
            subjectGoodsMapper.batchInsert(subjectGoodsList);
        }
    }

    //修改专题后同时需要修改已经存在于模板1的首页数据、分类专题的专题
    private void updateSubjectInHomepage(Long subjectID) throws Exception {
        Map<String, Object> param = new HashMap<>();
        param.put("muban", 1);
        List<Homepage> homepageList = homepageMapper.selectAll(param);
        for (Homepage homepage : homepageList) {
            if (homepage.getId() == 6) {
                continue;
            }
            if (homepage.getId() == 7) {  //更多专题项
                if (homepage.getObejctList() != null) {
                    if (homepage.getObejctList().contains(subjectID.toString())) {
                        JSONObject jsonObject = JSONObject.fromObject(homepage.getObejctList());
                        JSONArray jsonArray = JSONArray.fromObject(jsonObject.get("subjectList"));
                        List<Subject> subjectList = (List) JSONArray.toCollection(jsonArray, Subject.class);
                        List<Subject> sbList = new ArrayList<>();
                        for (Subject subject : subjectList) {
                            if (subject.getId().equals(subjectID)) {
                                Subject subjectNew = subjectMapper.selectByPrimaryKey(subjectID);
                                BeanUtils.copyProperties(subject, subjectNew);
                            }
                        }
                        JSONObject jsonObject1 = new JSONObject();
                        jsonObject1.put("subjectList", subjectList);
                        updateHomepageMoreTitle(jsonObject1);
                    }
                }
            } else {
                if (homepage.getSubjectID() != null) {
                    if (homepage.getSubjectID().equals(subjectID)) {
                        Subject subject = subjectMapper.selectByPrimaryKey(subjectID);
                        updateHomepageMiddle(subject, homepage.getId());
                    }
                }
            }
        }
        //修改专题不需要修改
        /*Subject subject = subjectMapper.selectByPrimaryKey(subjectID);
        Map<String, Object> map = new HashMap<>();
        map.put("subjectID", subjectID);
        map.put("clazzImage", subject.getBannerImg());
        DataResult result = HttpUtil.httpPost(ProConstants.operateClazzSubject, map, restTemplate);
        if (result.getIsSuccess() != 1) {
            throw new ServiceException("修改分类专题中的专题失败,请重试", RestConst.ErrorCode.SERVICE_FAIL);
        }*/
    }

    private Map<String, Object> getGoodsPrice(List<Long> list, Long userID) {
        DataResult result = new DataResult();
        if (userID != null && userID != 0) {
            result = HttpUtil.httpPost(ProConstants.getGoodsPriceByIDListV2 + userID, list, restTemplate);
        } else {
            result = HttpUtil.httpPost(ProConstants.getGoodsPriceByIDList, list, restTemplate);
        }
        if (result.getIsSuccess() != 1) {
            throw new ServiceException("调用bank服务查询商品价格接口出错", RestConst.ErrorCode.SERVICE_FAIL);
        }
        return (Map<String, Object>) result.getData();
    }

    private Map<String, Object> getShopGoodsPrice(List<Long> list, Long shopID) {
        DataResult result = new DataResult();
        if (shopID != null && shopID != 0) {
            result = HttpUtil.httpPost(ProConstants.getGoodsPriceByIDListShop + shopID, list, restTemplate);
        } else {
            result = HttpUtil.httpPost(ProConstants.getGoodsPriceByIDList, list, restTemplate);
        }
        if (result.getIsSuccess() != 1) {
            throw new ServiceException("调用bank服务查询商品价格接口出错", RestConst.ErrorCode.SERVICE_FAIL);
        }
        return (Map<String, Object>) result.getData();
    }

    public Object deleteByCompanyIDAndGoodsID(Long companyID, Long goodsID) {
        if (Objects.equal(companyID,SystemContext.getCompanyID())){
            companyID=null;//删除所用引用goods的 专题明细。
        }
       return subjectGoodsMapper.deleteByCompanyIDAndGoodsID(companyID,goodsID);
    }
}
